#include <pcre.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main(){
    const char* error;
    int errorOffset;
    pcre* re;

    re=pcre_compile("\\w+",0,&error,&errorOffset,NULL);
    if(re==NULL){
        printf("pattern error %s at %d\n",error,errorOffset);
        return 1;
    }
    const char* hello="hello this is test";
    int ovector[10];
    int rc;
    rc=pcre_exec(re,NULL,hello,strlen(hello),0,0,ovector,10);
    if(rc<0){
        switch(rc){
            case PCRE_ERROR_NOMATCH:
                printf("no match \n");
                break;
            default:
                printf("error match %d\n",rc);
        }
        pcre_free(re);
        return 1;
    }
    int i;
    for(i=1;i<=rc;i++){
        printf("match len %d : %s\n",ovector[i*2-1]-ovector[i*2],hello+ovector[i*2-1]);
    }
    pcre_free(re);
}
